module.exports = {
  devServer: {
    port: 80,
    proxy: {
      "/api": {
        target: process.env.REACT_APP_API_URL,
        changeOrigin: true,
        pathRewrite: { "^/api": "" },
      },
    },
  },
  webpack: {
    configure(webpackConfig) {
      if (webpackConfig.mode === "production") {
        if (!webpackConfig.optimization) webpackConfig.optimization = {};
        webpackConfig.optimization.splitChunks = {
          chunks: "all",
          cacheGroups: {
            // 优先拆分较大的组件库
            antd: {
              name: "antd-chunk",
              // 匹配
              test: /antd/,
              // 优先级
              priority: 100,
            },
            // 其次是reactDom
            reactDom: {
              name: "reactDom-chunk",
              test: /react-dom/,
              priority: 99,
            },
            // 最后把剩余所有依赖统一拆分
            vendors: {
              name: "vendors-chunk",
              test: /node_modules/,
              priority: 98,
            },
          },
        };
      }
      return webpackConfig;
    },
  },
};
